package sample;

import javafx.fxml.FXML;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import sample.Shapes.ArrowLine;
import sample.Shapes.Circle;
import sample.Shapes.Ellipse;

import java.util.ArrayList;
import java.util.List;

public class Controller {
    @FXML
    private Canvas canv; // FXML注入的Canvas组件

    private GraphicsContext gc; // 用于绘图的上下文对象


    private static final int CANVAS_WIDTH = 1000; // 画布宽度
    private static final int CANVAS_HEIGHT = 600; // 画布高度

//    double lineStartX, lineStartY; // 线的起点
//    double lineEndX, lineEndY;     // 线的终点
//    private int draggingEndpoint = -1; // 当前正在拖动的线端点（0: 起点，1: 终点，-1: 无）
//
//    double circleStartX, circleStartY;
//    double squareStartW, squareStartH;
//    private int draggingCircle = -1;
//    private static final double CIRCLE_SIZE = 100;
//
//    double RhombusStartX, RhombusStartY;
//    double RhombusStartW, RhombusStartH;
//    private int draggingRhombus = -1;


    List<Object> totalList = new ArrayList<>();
    List<ArrowLine> arrowLines=new ArrayList<>();
    List<Circle> circles=new ArrayList<>();
    List<Ellipse> ellipses=new ArrayList<>();

    // 初始化方法，由FXML调用
    public void initialize() {
        gc = canv.getGraphicsContext2D(); // 获取绘图上下文

        ArrowLine arrowLine=new ArrowLine(gc,canv,50,50,100,100);
        arrowLines.add(arrowLine);
        ArrowLine arrowLine1=new ArrowLine(gc,canv,400,150,200,200);
        arrowLines.add(arrowLine1);

        Circle circle=new Circle(gc,canv,200,200,100,100);
        circles.add(circle);
        Circle circle1=new Circle(gc,canv,500,250,100,100);
        circles.add(circle1);

        Ellipse ellipse=new Ellipse(gc,canv,300,400,100,60);
        ellipses.add(ellipse);
        Ellipse ellipse1=new Ellipse(gc,canv,400,200,100,40);
        ellipses.add(ellipse1);

        totalList.add(arrowLines);
        totalList.add(circles);
        totalList.add(ellipses);

        for (ArrowLine single:arrowLines){
            single.setTotalList(totalList);
        }

        for (Circle single:circles){
            single.setTotalList(totalList);
        }

        for (Ellipse single:ellipses){
            single.setTotalList(totalList);
        }
    }
}
